<template>
	<view>
		<u-navbar placeholder fixed autoBack border title="人员调岗">
			<view slot="right" class="d-flex">
				<u-icon name="plus" size="18" @click="transferAdd"></u-icon>
				<u-icon class="d-m-l-16" name="edit-pen" size="24" @click="(mode = 0), (show = true)"></u-icon>
				<!-- <u-icon class="d-m-l-16" name="search" size="24" @click="transferSearch" color="#162233"></u-icon> -->
			</view>
		</u-navbar>
		<d-select :options="options" @query="searchData"></d-select>
		<view class="d-p-30">
			<u-checkbox-group v-model="ids">
				<u-swipe-action class="d-flex-1" ref="action">
					<u-swipe-action-item
						class="d-m-b-30 card2"
						v-for="(item, index) in list"
						:key="item.id"
						:options="_action(item)"
						@click="action($event, item, _action(item))"
						:threshold="30"
					>
						<view class="card d-flex d-p-30" :key="index">
							<template v-if="mode != 0">
								<view><u-checkbox shape="circle" :disabled="item.ywzt != 1" :name="item.id"></u-checkbox></view>
							</template>
							<view class="d-flex-1">
								<view class="d-flex" style="color: #5D6672;">
									<view class="d-font-24" style="flex: 3;">
										<text style="">单位状态</text>
										<text class="d-m-l-20" :style="{
											color: _color(item.ywzt)
										}">{{ item.ywzt | _ywzt }}</text>
									</view>
									<view class="d-font-24" style="flex: 3;">
										<text style="">班组人数</text>
										<text class="d-m-l-20" style="color: #162233;">{{ item.cyrs || 0 }}人</text>
									</view>
								</view>
								<view class="d-flex d-m-t-20" style="color: #5D6672;">
									<view class="d-font-24" style="flex: 3;">
										<text style="">班组名称</text>
										<text class="d-m-l-20" style="color: #162233;">{{ item.groupname }}</text>
									</view>
								</view>
								<view class="d-flex d-m-t-20" style="color: #5D6672;">
									<view class="d-font-24" style="flex: 3;">
										<text style="">所属单位</text>
										<text class="d-m-l-20" style="color: #162233;">{{ item.deptName }}</text>
									</view>
								</view>
								<view class="d-flex d-m-t-20" style="color: #5D6672;">
									<view class="d-font-24" style="flex: 3;">
										<text style="">办理时间</text>
										<text class="d-m-l-20" style="color: #162233;">{{ item.createTime }}</text>
									</view>
								</view>
								<!-- <view class="d-flex d-m-t-20" style="color: #5D6672;">
									<view class="d-font-24" style="flex: 3;">
										<text style="">班组人数</text>
										<text class="d-m-l-20" style="color: #162233;">39人</text>
									</view>
									<view v-if="mode == 1" class="d-flex d-row-right" style="flex: 3;">
										<view class="d-m-l-20"><u-button text="提交" size="mini" shape="circle"></u-button></view>
										<view class="d-m-l-20"><u-button text="删除" size="mini" shape="circle"></u-button></view>
									</view>
								</view> -->
							</view>
						</view>
					</u-swipe-action-item>
				</u-swipe-action>
			</u-checkbox-group>
			<template v-if="list.length <= 0">
				<view style="padding: 10vh;"><u-empty icon="/static/image/none.png" text="暂无数据"></u-empty></view>
			</template>
		</view>

		<view class="bottom u-safe-area-inset-bottom" v-if="show">
			<view class="u-safe-area-inset-bottom d-flex u-border-top">
				<template v-if="mode == 0">
					<view class="d-flex-1 d-m-r-20"><u-button text="取消" @click="(mode = 0), (show = false)"></u-button></view>
					<view class="d-flex-1 d-m-r-20"><u-button text="业务提交" @click="mode = 1"></u-button></view>
					<view class="d-flex-1"><u-button text="业务删除" @click="mode = 2"></u-button></view>
				</template>
				<template v-else-if="mode == 1">
					<view class="d-flex-1 d-m-r-20"><u-button text="取消" @click="(mode = 0), (show = false)"></u-button></view>
					<view class="d-flex-1"><u-button text="提交" @click="showSubmit = true"></u-button></view>
				</template>
				<template v-else>
					<view class="d-flex-1 d-m-r-20"><u-button text="取消" @click="(mode = 0), (show = false)"></u-button></view>
					<view class="d-flex-1"><u-button text="删除" @click="showDelete = true"></u-button></view>
				</template>
			</view>
		</view>

		<u-modal :show="showDelete" :showCancelButton="true" title="温馨提示" content="此操作不可逆, 是否确认删除该数据?" @cancel="showDelete = false" @confirm="del"></u-modal>
		<u-modal
			:show="showSubmit"
			:showCancelButton="true"
			title="温馨提示"
			content="此操作不可逆, 是否确认提交该业务数据?"
			@cancel="showSubmit = false"
			@confirm="submit"
		></u-modal>
	</view>
</template>

<script>
import { gafferlist, ssdwList, delMg, submitMg } from '../../../common/api.js';
export default {
	data() {
		return {
			mode: 0,
			options: [],
			queryParams: {},
			list: [],
			pageNum: 1,
			pageSize: 20,
			pageLast: 1,
			show: false,
			showDelete: false,
			showSubmit: false,
			ids: []
		};
	},
	watch: {
		show(v) {
			if (v) {
				this.ids = [];
				this.$refs.action.closeOther();
			}
		}
	},
	onReachBottom() {
		if (this.pageLast > this.pageNum) {
			++this.pageNum;
			this.getData().then(e => {
				this.list = this.list.concat(e.data);
			});
		}
	},
	onLoad() {
		ssdwList({
			params: {
				gcbh: this.$user.ssgcxx[this.$appIndex].gcbh, // 所属项目编号
				deptId: this.$user.ssgcxx[this.$appIndex].deptId // 所属部门编号
			}
		}).then(e => {
			let deptId = [];
			deptId = e.data.map(e => {
				return {
					id: e.deptId,
					label: e.deptName
				};
			});
			this.options = [
				{
					label: '所属单位',
					name: 'deptId',
					children: deptId
				},
				{
					label: '业务状态',
					name: 'ywzt',
					children: [{ id: 0, label: '办结' }, { id: 1, label: '未提交' }, { id: 2, label: '注销' }, { id: 3, label: '审批中' }]
				}
			];
		});
	},
	filters: {
		_ywzt(e) {
			return ['办结', '未提交', '注销', '审批中'][e];
		},
		
	},
	onShow() {
		this.init();
	},
	methods: {
		_color(e) {
			return ['#000', '#999', 'red', 'blue'][e];
		},
		init() {
			this.show = false;
			this.pageNum = 1;
			this.getData().then(e => {
				this.list = e.data;
				this.pageLast = Math.ceil(e.total / this.pageSize);
			});
		},
		getData() {
			return gafferlist({
				params: {
					pageNum: this.pageNum, //	当前页【必传】
					pageSize: this.pageSize, //     每页条数【必传】
					gcbh: this.$user.ssgcxx[this.$appIndex].gcbh, // 项目业务编号【必传】
					...this.queryParams
				}
			});
		},
		transferSearch() {
			uni.$u.route({
				url: '/pages/index/member/transferSearch'
			});
		},
		transferAdd() {
			uni.removeStorageSync('bz');
			uni.$u.route({
				url: '/pages/index/member/transferAdd'
			});
		},
		searchData(e) {
			this.queryParams = e;
			this.init();
		},
		action(e, item, option) {
			if (option[e.index].name == 'delete') {
				this.ids = [item.id];
				this.showDelete = true;
			} else if (option[e.index].name == 'submit') {
				this.ids = [item.id];
				this.showSubmit = true;
			} else if (option[e.index].name == 'edit') {
				uni.removeStorageSync('bz');
				this.$refs.action.closeOther();
				uni.$u.route({
					url: '/pages/index/member/transferAdd',
					params: {
						id: item.id
					}
				});
			}
		},
		del() {
			this.showDelete = false;
			this.$refs.action.closeOther();
			if (this.ids.length <= 0) {
				return uni.$u.toast('请选择要操作的数据');
			}
			delMg({
				params: {
					id: this.ids.join(',')
				}
			}).then(e => {
				this.show = false;
				this.mode = 0;
				uni.$u.toast('删除成功');
				this.init();
			});
		},
		submit() {
			this.showSubmit = false;
			this.$refs.action.closeOther();
			if (this.ids.length <= 0) {
				return uni.$u.toast('请选择要操作的数据');
			}
			submitMg({
				params: {
					id: this.ids.join(',')
				}
			}).then(e => {
				this.show = false;
				this.mode = 0;
				uni.$u.toast('提交成功');
				this.init();
			});
		}
	},
	computed: {
		_action() {
			return function(item) {
				if (item.ywzt == 1) {
					return [
						{
							text: '提交',
							name: 'submit',
							style: {
								backgroundColor: '#3c9cff',
								fontSize: '26rpx'
							}
						},
						{
							text: '编辑',
							name: 'edit',
							style: {
								backgroundColor: '#002081',
								fontSize: '26rpx'
							}
						},
						{
							text: '删除',
							name: 'delete',
							style: {
								backgroundColor: '#f56c6c',
								fontSize: '26rpx'
							}
						}
					];
				} else {
					return [
						{
							text: '查看',
							name: 'edit',
							style: {
								backgroundColor: '#3c9cff',
								fontSize: '26rpx'
							}
						}
					];
				}
			};
		}
	}
};
</script>

<style lang="scss">
.d-sel {
	position: fixed;
	left: 0;
	right: 0;
	background-color: #ffffff;
	z-index: 999;
	& > view {
		height: 68rpx;
	}
	box-shadow: 0rpx 5rpx 10rpx rgba(0, 0, 0, 0.05);
	.u-border-right {
		border-color: #eeeeee !important;
	}
}
.card {
	box-shadow: 0rpx 5rpx 10rpx rgba(0, 0, 0, 0.05);
	border-radius: 10rpx;
	background-color: #ffffff;
}
page {
	background-color: #fbfcfc;

	.bottom {
		height: 140rpx;
		box-sizing: content-box;
		& > view {
			height: 140rpx;
			position: fixed;
			left: 0;
			right: 0;
			bottom: 0;
			background-color: #ffffff;
			padding-left: 30rpx;
			padding-right: 30rpx;
			z-index: 9999;
		}
	}
}
</style>
